﻿// Decompiled with JetBrains decompiler
// Type: Bannerlord.ModuleManager.SubModuleInfoExtended
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml;

#nullable enable
namespace Bannerlord.ModuleManager
{
  internal record SubModuleInfoExtended()
  {
    public string Name { get; set; } = string.Empty;

    public string DLLName { get; set; } = string.Empty;

    public IReadOnlyList<string> Assemblies { get; set; } = (IReadOnlyList<string>) Array.Empty<string>();

    public string SubModuleClassType { get; set; } = string.Empty;

    public IReadOnlyDictionary<string, IReadOnlyList<string>> Tags { get; set; } = (IReadOnlyDictionary<string, IReadOnlyList<string>>) new Dictionary<string, IReadOnlyList<string>>();

    public SubModuleInfoExtended(
      string name,
      string dllName,
      IReadOnlyList<string> assemblies,
      string subModuleClassType,
      IReadOnlyDictionary<string, IReadOnlyList<string>> tags)
    {
      this.Name = name;
      this.DLLName = dllName;
      this.Assemblies = assemblies;
      this.SubModuleClassType = subModuleClassType;
      this.Tags = tags;
    }

    public static SubModuleInfoExtended? FromXml(XmlNode? subModuleNode)
    {
      if (subModuleNode == null)
        return (SubModuleInfoExtended) null;
      string str1 = subModuleNode.SelectSingleNode("Name")?.Attributes?["value"]?.InnerText ?? string.Empty;
      string str2 = subModuleNode.SelectSingleNode("DLLName")?.Attributes?["value"]?.InnerText ?? string.Empty;
      string str3 = subModuleNode.SelectSingleNode("SubModuleClassType")?.Attributes?["value"]?.InnerText ?? string.Empty;
      string[] strArray = Array.Empty<string>();
      int? count;
      if (subModuleNode.SelectSingleNode("Assemblies") != null)
      {
        XmlNodeList xmlNodeList = subModuleNode.SelectSingleNode("Assemblies")?.SelectNodes("Assembly");
        strArray = new string[xmlNodeList != null ? xmlNodeList.Count : 0];
        int i = 0;
        while (true)
        {
          int num = i;
          count = xmlNodeList?.Count;
          int valueOrDefault = count.GetValueOrDefault();
          if (num < valueOrDefault & count.HasValue)
          {
            strArray[i] = xmlNodeList?[i]?.Attributes?["value"]?.InnerText ?? string.Empty;
            ++i;
          }
          else
            break;
        }
      }
      XmlNodeList xmlNodeList1 = subModuleNode.SelectSingleNode("Tags")?.SelectNodes("Tag");
      Dictionary<string, List<string>> source = new Dictionary<string, List<string>>();
      int i1 = 0;
      while (true)
      {
        int num1 = i1;
        count = xmlNodeList1?.Count;
        int valueOrDefault = count.GetValueOrDefault();
        if (num1 < valueOrDefault & count.HasValue)
        {
          string innerText1 = xmlNodeList1?[i1]?.Attributes?["key"]?.InnerText;
          string innerText2;
          int num2;
          if (innerText1 != null)
          {
            innerText2 = xmlNodeList1[i1]?.Attributes?["value"]?.InnerText;
            num2 = innerText2 != null ? 1 : 0;
          }
          else
            num2 = 0;
          if (num2 != 0)
          {
            List<string> stringList;
            if (source.TryGetValue(innerText1, out stringList))
              stringList.Add(innerText2);
            else
              source[innerText1] = new List<string>()
              {
                innerText2
              };
          }
          ++i1;
        }
        else
          break;
      }
      return new SubModuleInfoExtended()
      {
        Name = str1,
        DLLName = str2,
        Assemblies = (IReadOnlyList<string>) strArray,
        SubModuleClassType = str3,
        Tags = (IReadOnlyDictionary<string, IReadOnlyList<string>>) new ReadOnlyDictionary<string, IReadOnlyList<string>>((IDictionary<string, IReadOnlyList<string>>) source.ToDictionary<KeyValuePair<string, List<string>>, string, IReadOnlyList<string>>((Func<KeyValuePair<string, List<string>>, string>) (x => x.Key), (Func<KeyValuePair<string, List<string>>, IReadOnlyList<string>>) (x => (IReadOnlyList<string>) new ReadOnlyCollection<string>((IList<string>) x.Value))))
      };
    }

    public override string ToString() => this.Name + " - " + this.DLLName;

    public virtual bool Equals(SubModuleInfoExtended? other)
    {
      if ((object) other == null)
        return false;
      return (object) this == (object) other || this.Name == other.Name;
    }

    public override int GetHashCode() => this.Name.GetHashCode();

    [CompilerGenerated]
    protected virtual bool PrintMembers(StringBuilder builder)
    {
      RuntimeHelpers.EnsureSufficientExecutionStack();
      builder.Append("Name = ");
      builder.Append((object) this.Name);
      builder.Append(", DLLName = ");
      builder.Append((object) this.DLLName);
      builder.Append(", Assemblies = ");
      builder.Append((object) this.Assemblies);
      builder.Append(", SubModuleClassType = ");
      builder.Append((object) this.SubModuleClassType);
      builder.Append(", Tags = ");
      builder.Append((object) this.Tags);
      return true;
    }

    [CompilerGenerated]
    protected SubModuleInfoExtended(SubModuleInfoExtended original)
    {
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      this.\u003CName\u003Ek__BackingField = original.\u003CName\u003Ek__BackingField;
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      this.\u003CDLLName\u003Ek__BackingField = original.\u003CDLLName\u003Ek__BackingField;
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      this.\u003CAssemblies\u003Ek__BackingField = original.\u003CAssemblies\u003Ek__BackingField;
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      this.\u003CSubModuleClassType\u003Ek__BackingField = original.\u003CSubModuleClassType\u003Ek__BackingField;
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      this.\u003CTags\u003Ek__BackingField = original.\u003CTags\u003Ek__BackingField;
    }
  }
}
